#ifndef __COMMANDLINEMGRBASE_H__
#define __COMMANDLINEMGRBASE_H__

#include "plat/nonecopyable.h"
#include "lib/cqueue.h"
#include "os/msgqueue.h"
#include "os/thread.h"
#include "os/recursivemutex.h"
#include <map>
#include <vector>
#include "commandlinedef.h"

//注册命令
//为了节约空间，使用DEF_CLI_COMMAND
#define DEF_CLI_COMMAND(name, help, func) {name, help, &func}

class CommandLineMgrBase  : public NoneCopyable
{
public:
    explicit CommandLineMgrBase();
    virtual ~CommandLineMgrBase();  

public:
    void RegisterCommandTable(const CommandRegisterItem* cmds, int len);
    void UnRegisterCommand(const std::string &name);
    void ClearAllCommand();

    void ProcessCommand(CommandParamItem &item);

private:
    CommandRegisterItem* FindCommand(const std::string &name);
    
public:
    //内置指令
    static void Help(CommandParamItem &item);
    static void Clear(CommandParamItem &item);
    
    static void SystemRest(CommandParamItem &item);
    static void ReadCpuTemperature(CommandParamItem &item);
    static void ListThread(CommandParamItem &item);
    static void ListThreadState(CommandParamItem &item);
    static void GetOsThreadCount(CommandParamItem &item);
    static void ReadSpaceMem(CommandParamItem &item);
    static void GetCpuId(CommandParamItem &item);
    static void GetCpuFlashSize(CommandParamItem &item);
    static void GetCpuFrequency(CommandParamItem &item);
    static void GetCpuCurrentMs(CommandParamItem &item);
    static void ShowFWVersion(CommandParamItem &item);

    static void LogSetEnable(CommandParamItem &item);
    static void VisualOscSetEnable(CommandParamItem &item);

    //内建指令
    void BuildBuiltinCommand();

private:
    void ShowHelpImpl(CommandParamItem &item);

private:
    std::map<std::string, CommandRegisterItem*> m_commandItems;
    RecursiveMutex m_mutex;
};

#endif // __COMMANDLINEMGRBASE_H__
